function BowlingGame(players)
{
    console.log("Skapar nytt spel");  
    
    this.getPlayers = function() { return players; };
    
    this.setPlayers = function(_players) {
        
        if (!(_players instanceof Array))
        {
            throw new Error("Bowling game takes an array as argument.");
        }
        
        
        for (player in _players)
        {
            if (!(_players[player] instanceof Player))
            {
                throw new Error ("Bowling game array only support Player.");
            }
        }
        
        players = _players
    }
    
    this.setPlayers(players);
}

BowlingGame.prototype.play = function() {
    
    var players = this.getPlayers();
    
    for (var rounds = 0; rounds < 50; rounds++)
    {
        for (var p = 0; p < players.length; p++)
        {
            players[p].updateScore(toss());
        }
    }
    
    console.log(players[0].getScore());
    
    function toss() {
        
        var point = Math.floor(Math.random() * 11);
        return point;
    }
}

BowlingGame.prototype.showScoreBoard = function() {
    
    var players = this.getPlayers();
    
    document.write("<h3>Scoreboard</h3>");
    
    for (var p = 0; p < players.length; p++)
    {
        document.write(players[p].getName() + ": " + players[p].getScore() + " poäng<br />");
    }
}